# -*- coding:utf-8 -*-
__author__ = 'weikai'
import json
import logging
from twisted.internet import defer, task
from stompest.config import StompConfig
from stompest.async import Stomp
from stompest.async.listener import ReceiptListener
import settings as se
'''
        BATCH_PROCESS_QUEUE,  -- 批量队列
        FILL_UP_QUEUE, -- 补全 队列
        PICC_QUEUE, -- 中国人保队列
        CHINA_CONTINENT_QUEUE, -- 中国大地队列
        CHINA_JOINT_QUEUE; -- 中华联合队列
'''
class Producer(object):
    test='/queue/test'
    QUEUE='/queue/FILL_UP_QUEUE'
    FILL_UP_QUEUE = '/queue/FILL_UP_QUEUE'
    PICC_QUEUE='/queue/PICC_QUEUE'
    CHINA_CONTINENT_QUEUE='/queue/CHINA_CONTINENT_QUEUE'
    CHINA_JOINT_QUEUE='/queue/CHINA_JOINT_QUEUE'
    COMPLETE_PLATE_NUMBER="/queue/COMPLETE_PLATE_NUMBER"
    def __init__(self, config=None):
        if config is None:
            config = StompConfig('tcp://127.0.0.1:61613')
            #config = StompConfig('tcp://118.178.232.65:61613')
        self.config = config

    @defer.inlineCallbacks
    def run(self, _):
        t=[{'VIN_NO':'LHGCM567852063612','INSURE_CAR_ID':75},{'VIN_NO':'UU6MF48411D017474','INSURE_CAR_ID':76},{'VIN_NO':'LVSFDFAB6AN188127','INSURE_CAR_ID':77},{'VIN_NO':'LDNH4LGE970154536','INSURE_CAR_ID':78}]
        dd=[{"firstRegister": "2001-06-12", "insureCarId": 3341, "cityCode": "32010000", "vinNo": "LSVCH033X12032808", "plateNumber": "苏A0XN01", "preminuEndDate": "2018-01-15 00:00:00.0", "vehicleBrand": "SVW7182CFi", "custName": "赵伦萍", "phone": "", "flag": 1, "engineNo": "AYJ0017013", "licenseDateStr": "", "licenseDate": "", "address": "","identitCard": "320123197809122018", "firstRegisterStr": "", "crawlDate": "2017-01-14 16:08:17.0", "preminuStartDate": "2017-01-15 00:00:00.0"}]
        dd2=[{"address":"","amount":"","carNickAmount":"","cityCode":"","crawlDate":"","custName":"","engineNo":"","firstRegister":"","firstRegisterStr":"","flag":0,"identitCard":"","insuranceType":[{"carDamageBenchMarkPremium":"1","carDamagePremium":"1","carFireBrokenBenchMarkPremium":"0","carFirePremium":"1","carNickBenchMarkPremium":"0","carNickPremium":{"Amount":"","isCheck":"0"},"carTheftBenchMarkPremium":"0","carTheftPremium":"1","compulsoryInsurance":"1","driverDutyBenchMarkPremium":"1","driverDutyPremium":{"Amount":"10000","isCheck":"1"},"engineWadingBenchMarkPremium":"0","engineWadingPremium":"1","glassBrokenPremium":"1","insuranceTypeGroup":"1_11_12_2_20_3_30_4_5_50_6_60_7_9","insuranceTypeGroupId":"138","nAggTax":"1","otherHurtBenchMarkPremium":"1","otherHurtPremium":{"Amount":"500000","isCheck":"1"},"passengerBenchMarkPremium":"1","passengerDutyPremium":{"Amount":"10000","isCheck":"1"}}],"insuranceTypeGroup":"","insureCarId":3769,"insureTypeGroupId":"","isPhone":"1","licenseDate":"","licenseDateStr":"","phone":"","plateNumber":"苏DZ866Z","preInsureEndDate":"","preminuEndDate":"","preminuStartDate":"","sessionId":"55d23ec2873c9048404b020c597c032a33286544","vehicleBrand":"","vinNo":"LJ8F7D5H5FB003062"}]
        dd3=[
    {
        "address": "",
        "cityCode": "32010000",
        "crawlDate": "2017-02-01 10:35:35.0",
        "custName": "张宇",
        "engineNo": "GM9594",
        "firstRegister": "2016-05-03",
        "firstRegisterStr": "",
        "flag": 0,
        "identitCard": "530322198104258634",
        "insureCarId": 3633,
        "isPhone": "1",
        "licenseDate": "",
        "licenseDateStr": "",
        "phone": "",
        "plateNumber": "苏A2G3K2",
        "preminuEndDate": "2018-02-28 00:00:00.0",
        "preminuStartDate": "2017-03-01 00:00:00.0",
        "sessionId": "d65234712e77be49cc013c7f00a368eee192323c",
        "vehicleBrand": "FV7166BABBG",
        "vinNo": "LFV2A21KXG4048148",
        "insuranceType": {
            "insuranceTypeGroupId": "6",
            "insuranceTypeGroup": "88888888",
            "compulsoryInsurance": "1",
            "nAggTax": "1",
            "otherHurtPremium": {
                "isCheck": "1",
                "Amount": "500000"
            },
            "carNickPremium": {
                "isCheck": "1",
                "Amount": "2000"
            },
            "driverDutyPremium": {
                "isCheck": "1",
                "Amount": "10000"
            },
            "passengerDutyPremium": {
                "isCheck": "1",
                "Amount": "10000"
            },
            "glassBrokenPremium": "1",
            "carFirePremium": "1",
            "engineWadingPremium": "1",
            "carTheftPremium": "1",
            "carDamagePremium": "1",
            "carDamageBenchMarkPremium": "1",
            "otherHurtBenchMarkPremium": "1",
            "carTheftBenchMarkPremium": "1",
            "driverDutyBenchMarkPremium": "1",
            "passengerBenchMarkPremium": "1",
            "carNickBenchMarkPremium": "1",
            "carFireBrokenBenchMarkPremium": "1",
            "engineWadingBenchMarkPremium": "1"
        }
    }
]
        #非续保
        #dd4=[{"plateNumber":"苏NXZ170","insureCarId":3442}]
        #续保
        dd4=[
  {
    "plateNumber": "苏AQ181L",
    "insureCarId": 3797,
    "sessionId": 'sessionId',
    "isPhone": "1",
    "insuranceType": [{
      "insuranceTypeGroupId": "6",
      "insuranceTypeGroup": "88888888",
      'compulsoryInsurance': "1",
      'nAggTax': '1',
      'otherHurtPremium': {
        "isCheck": "0",
        "Amount": "500000"
      },
      'carNickPremium': {
        "isCheck": "0",
        "Amount": "2000"
      },
      'driverDutyPremium': {
        "isCheck": "0",
        "Amount": "10000"
      },
      'passengerDutyPremium': {
        "isCheck": "0",
        "Amount": "10000"
      },
      'glassBrokenPremium': "0",
      'carFirePremium': "0",
      'engineWadingPremium': "0",
      'carTheftPremium': "0",
      'carDamagePremium': "0",
      'carDamageBenchMarkPremium': '0',
      'otherHurtBenchMarkPremium': '0',
      'carTheftBenchMarkPremium': '0',
      'driverDutyBenchMarkPremium': '0',
      'passengerBenchMarkPremium': '0',
      'carNickBenchMarkPremium': '0',
      'carFireBrokenBenchMarkPremium': '0',
      'engineWadingBenchMarkPremium': '0'
    }]
  }
]

        dd6=[{"firstRegister": "", "custName": "", "vehicleBrand": "", "crawlDate": "", "firstRegisterStr": "", "plateNumber": "苏AK380P", "amount": "", "preInsureEndDate": "2017-03-28", "engineNo": "", "identitCard": "", "insureCarId": 3797, "cityCode": "", "vinNo": "LSVFG66R1D2132738", "phone": "", "flag": 0, "address": "", "preminuStartDate": "", "isPhone": "1", "insuranceTypeGroup": "", "insureTypeGroupId": "", "preminuEndDate": "", "carNickAmount": "", "insuranceType": [{"carDamageBenchMarkPremium": "1", "driverDutyPremium": {"Amount": "10000", "isCheck": "1"}, "passengerDutyPremium": {"Amount": "10000", "isCheck": "1"}, "carDamagePremium": "1", "driverDutyBenchMarkPremium": "1", "carFireBrokenBenchMarkPremium": "0", "carTheftPremium": "1", "otherHurtBenchMarkPremium": "1", "carTheftBenchMarkPremium": "0", "engineWadingBenchMarkPremium": "1", "carNickPremium": {"Amount": "20000", "isCheck": "1"}, "nAggTax": "1", "carFirePremium": "1", "carNickBenchMarkPremium": "1", "engineWadingPremium": "1", "passengerBenchMarkPremium": "0", "insuranceTypeGroupId": "183", "otherHurtPremium": {"Amount": "500000", "isCheck": "1"}, "glassBrokenPremium": "0", "compulsoryInsurance": "1", "insuranceTypeGroup": "1_11_110_12_2_20_3_30_4_5_50_6_8_20000_80_9"}], "sessionId": "2bbcd99cd95d9b8fdf98b29e163686f6bca30736", "licenseDateStr": "", "licenseDate": ""}]

        dd5=[{"address":"江苏徐州","cityCode":"32030000","crawlDate":"","custName":"张三","engineNo":"WWEWRWR456","firstRegister":"2016-9-12","firstRegisterStr":"","flag":0,"identitCard":"530322198104258634","insureCarId":3493,"isPhone":"","licenseDate":"2016-9-12","licenseDateStr":"","phone":"15950523561","plateNumber":"苏C123456","preminuEndDate":"","preminuStartDate":"","sessionId":"","vehicleBrand":"大众4556","vinNo":"123456"}]
        client = Stomp(self.config)
        yield client.connect()
        client.add(ReceiptListener(1.0))

        #yield client.send(self.QUEUE, json.dumps([ 'LFBGE3063EJG43961']).encode(), receipt='message-%s' % 'LFBGE3063EJG43961')
        # yield client.send(se.REAL_TIME_QUEUE, json.dumps(dd2).encode())
        yield client.send(se.COMPLETE_PLATE_NUMBER, json.dumps(dd6).encode())

        #yield client.send(self.QUEUE2, json.dumps([{'VIN_NO':'LHGCM567852063612','INSURE_CAR_ID':75},{'VIN_NO':'UU6MF48411D017474','INSURE_CAR_ID':76}]).encode())
        #client.disconnect(receipt='bye')
        client.disconnect()
        yield client.disconnected # graceful disconnect: waits until all receipts have arrived

if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)
    task.react(Producer().run)